Adding a new sort field to a report

In this example, we're going to add a sort field that currently isn't sorted.

You can put code like this in the General Declarations section.

Dim CRXReport As New CrystalReport1 
Dim CRXDatabaseField As CRAXDRT.DatabaseFieldDefinition 
Private Sub Form_Load() 

Currently there is no sort in this Report. To add the sort field Customer Name, the application must first get the {Customer.Customer Name} field from the Customer Table. This code accesses the first table to get the 2nd field.

Set CRXDatabaseField = CRXReport.Database.Tables.Item(1).Fields.Item(2) 

Now add the field to the SortFields Collection and set the Sort Order to ascending.

CRXReport.RecordSortFields.Add CRXDatabaseField, crAscendingOrder 

Note:    If the SortField is added while the Report is viewing, you will have to refresh the viewer before the new sort will be active. This can be done by clicking the Refresh button in the Report Viewer or refreshing the viewer through code. For example,

    CRViewer1.Refresh 
    CRViewer1.ReportSource = CRXReport 
    CRViewer1.ViewReport 
    End Sub


Seagate Software IMG Holdings, Inc.
http://www.seagatesoftware.com
Support services:
http://support.seagatesoftware.com